package eScrum.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class EncryptionUtil {
	public static String crypt(String passsword) {
		if (passsword == null || passsword.length() == 0) {
			throw new IllegalArgumentException("String to encrypt cannot be null or zero length");
		}

		StringBuffer hexString = new StringBuffer();

		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(passsword.getBytes());
			byte[] hashedPasssword = md.digest();

			for (int i = 0; i < hashedPasssword.length; i++) {
				if ((0xff & hashedPasssword[i]) < 0x10) {
					hexString.append("0" + Integer.toHexString((0xFF & hashedPasssword[i])));
				} else {
					hexString.append(Integer.toHexString(0xFF & hashedPasssword[i]));
				}
			}
		} catch (NoSuchAlgorithmException e) {

		}
		return hexString.toString();

	}

}
